#pragma once
#include <functional>
#include <stdio.h>
#include <string>
#include <iostream>
#include<unistd.h>

void serviceIO(int sock)
{
    // cout << sock << std::endl;
    char buffer[1024];
    std::cout<<111<<std::endl;
    while (true)
    {

        ssize_t n = read(sock, buffer, sizeof(buffer) - 1);
        if (n > 0)
        {
            // std::cout << 111 << std::endl;
            buffer[n] = 0;
            std::cout << "recv message: " << buffer << std::endl;
            std::string outbuffer = buffer;
            outbuffer += "server[echo]";
            write(sock, outbuffer.c_str(), outbuffer.size());
        }
        else if (n == 0)
        {
            // 代表client 退出
            logMessage(NORMAL, "client quit,me too;");
            break;
        }
    }
    close(sock);
}
class Task
{
public:
    // 申明一种函数类型
    using func_t = std::function<void(int)>;

    // 构造方法
    Task() {}
    Task(int sock, func_t func)
        : _sock(sock), _func(func)
    {
    }

    std::string operator()()
    {
        _func(_sock);
    }

private:
    int _sock;
    func_t _func;
};

